package com.haixiaoke.saas.repository.service.impl;

import com.haixiaoke.saas.repository.mapper.AppUserMapper;
import com.haixiaoke.saas.repository.pojo.AppUser;
import com.haixiaoke.saas.repository.service.IAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户表Service业务层处理
 *
 * @author panda
 * @date 2023-04-20
 */
@Service
public class AppUserServiceImpl implements IAppUserService {
    @Autowired
    private AppUserMapper appUserMapper;

    /**
     * 查询用户表的身份证
     *
     * @param id 用户表主键
     * @return 用户表
     */
    @Override
    public String selectAppUserById(String id) {
        return appUserMapper.selectAppUserById(id);
    }

    @Override
    public String selectPhoneByOrgId(Long orgId) {
        return appUserMapper.selectPhoneByOrgId(orgId);
    }

    @Override
    public String selectOpenIdById(String id) {
        return appUserMapper.selectOpenIdById(id);
    }

    @Override
    public String updateMobileDevicesId(String mobileDevicesId, String userId) {
        int i = appUserMapper.updateMobileDevicesId(mobileDevicesId, userId);
        String appUserId = userId;
        if (i == 0) {
            i = appUserMapper.updateMobileDevicesIdByEnterpriseUserId(mobileDevicesId, userId);
            if (i != 0) {
                AppUser appUser = appUserMapper.selectAppUserByEnterpriseUserId(mobileDevicesId);
                appUserId = appUser.getId();
            } else {
                appUserId = null;
            }
        }
        return appUserId;
    }

    @Override
    public List<AppUser> selectMobileDevicesIdByOrgId(Long orgId) {
        return appUserMapper.selectMobileDevicesIdByOrgId(orgId);
    }

    @Override
    public AppUser selectAppUserByUserId(String userId) {
        return appUserMapper.selectAppUserByUserId(userId);
    }

}
